#include "BTCOMConn.h"

CBTCOMConn::CBTCOMConn(void)
{
}

CBTCOMConn::~CBTCOMConn(void)
{
}

int CBTCOMConn::Connect()
{
    PORTEMUPortParams pp;
    memset (&pp, 0, sizeof(pp));
    pp.device = m_hBTAddr;
    pp.flocal = FALSE;
    pp.channel = 1;
    pp.uiportflags = RFCOMM_PORT_FLAGS_REMOTE_DCB;
    m_ConnHandle = RegisterDevice(L"COM", m_nCOMIndex, L"btd.dll", (DWORD)&pp);

    if (!m_ConnHandle)
    {
        return GetLastError();
    }

    return 0;
}

int CBTCOMConn::Remove()
{
    if (m_ConnHandle)
    {
        DeregisterDevice(m_ConnHandle);
        m_ConnHandle = NULL;
        return 0;
    }

    return -1;
}

bool CBTCOMConn::IsConnected()
{
    if (m_ConnHandle)
    {
        return true;
    }

    return false;
}

